﻿using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService.Symbols;

/// <summary>
///     元数据数据库字段中使用db声明的语句块内的属性定义，和一般的属性不同，
///     数据库字段属性不区分语言标签区域，单个字段中只保存单一的值。
/// </summary>
/// <param name="containingField">包含数据库属性列表的字段符号</param>
/// <param name="declaration">属性声明节点</param>
/// <param name="value">属性初始化值</param>
public class MetadataDbPropertySymbol(
    MetadataFieldSymbol containingField,
    MetadataProperty declaration,
    Expression? value = null)
    : MetadataSymbol(SymbolKinds.MetadataDbProperty, declaration)
{
    public override MetadataFieldSymbol ContainingSymbol { get; } = containingField;

    public Expression? Value { get; private set; } = value ?? declaration.Value;


    public override bool Redeclare(ISymbol symbol)
    {
        if (symbol is not MetadataDbPropertySymbol propertySymbol)
        {
            return false;
        }

        Value = propertySymbol.Value;
        return base.Redeclare(symbol);
    }
}